---------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/tomasdomingueziino/Dropbox/Research/jmp/current/data_new/shap
> efiles/raw/Ehrl_AMCgeneration_EE/_Crosswalk_1991_2010_2000.log
  log type:  text
 opened on:   8 Apr 2021, 10:37:59
   16
    4
    2
    0
(85 missing values generated)
(58 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(5592 missing values generated)
(58 real changes made)
(7 real changes made)
(58 real changes made)

. 
. *******************************************
. **** Auxiliary file 2: "matching.do"   ****
. **** matching of cluster-numbers       ****
. *******************************************
. **** Ehrl (2017) Estudos Economicos 47/1 ** 
. *******************************************
. 
. *** save the current data in use (to restore it later)
. save "current.dta", replace
(note: file current.dta not found)
file current.dta saved

. 
. *** keep only the two different group numbers
. keep clu`1' clu_new

. keep if clu_new!=.
(5534 observations deleted)

. sort clu`1' clu_new

. ** drop unecessary obs:
. drop if clu`1'==clu_new
(0 observations deleted)

. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
(0 observations deleted)

. 
. *** 1. check
. *** problem for several destinies (to be replaced by only 1 new clu-number)
.  count if clu`1'==clu`1'[_n-1]
    0

.  while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  save "temp.dta", replace
(note: file temp.dta not found)
file temp.dta saved

.  
.  *** 2. check if a problem will occur:
.  *** problem for cross-ref (a new cluster number is at the same time replaced b
> y another new one)
.  preserve 

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
. restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no:
. else {
. restore
. }

. 
. *** repeat this procedure several times
. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** final checks:
. assert clu`1'!=clu`1'[_n-1]

.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

.  assert r(N)==0

.  restore

. 
. // procedure is complete. restore data
. use "current.dta", clear

. 
. *** finally, replace cluster number of all mun of one group
. *** with the new number of the other group
. drop clu_new

. merge m:1 clu`1' using "temp.dta", nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                         5,534
        from master                     5,534  
        from using                          0  

    matched                                58  
    -----------------------------------------

. replace clu`1'=clu_new if clu_new!=.
(58 real changes made)

. drop clu_new

. 
. erase "temp.dta"

. erase "current.dta"

. cap erase "temp2.dta"

. 
end of do-file
missing matches per group #1

   ch_match |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      5,570       99.61       99.61
          1 |         16        0.29       99.89
          2 |          4        0.07       99.96
          3 |          2        0.04      100.00
------------+-----------------------------------
      Total |      5,592      100.00
   16
(5570 missing values generated)
(5592 missing values generated)
mis2000 was str22 now str32
(5543 real changes made)
(21 real changes made)
(18 real changes made)
(1 real change made)
(90 real changes made)
(0 real changes made)
   22
(22 real changes made)

. 
. *******************************************
. **** Auxiliary file 2: "matching.do"   ****
. **** matching of cluster-numbers       ****
. *******************************************
. **** Ehrl (2017) Estudos Economicos 47/1 ** 
. *******************************************
. 
. *** save the current data in use (to restore it later)
. save "current.dta", replace
(note: file current.dta not found)
file current.dta saved

. 
. *** keep only the two different group numbers
. keep clu`1' clu_new

. keep if clu_new!=.
(5570 observations deleted)

. sort clu`1' clu_new

. ** drop unecessary obs:
. drop if clu`1'==clu_new
(4 observations deleted)

. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
(0 observations deleted)

. 
. *** 1. check
. *** problem for several destinies (to be replaced by only 1 new clu-number)
.  count if clu`1'==clu`1'[_n-1]
    1

.  while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }
(1 real change made)
(1 real change made)
(0 observations deleted)
(0 observations deleted)
    0

.  save "temp.dta", replace
(note: file temp.dta not found)
file temp.dta saved

.  
.  *** 2. check if a problem will occur:
.  *** problem for cross-ref (a new cluster number is at the same time replaced b
> y another new one)
.  preserve 

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
. restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no:
. else {
. restore
. }

. 
. *** repeat this procedure several times
. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** final checks:
. assert clu`1'!=clu`1'[_n-1]

.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

.  assert r(N)==0

.  restore

. 
. // procedure is complete. restore data
. use "current.dta", clear

. 
. *** finally, replace cluster number of all mun of one group
. *** with the new number of the other group
. drop clu_new

. merge m:1 clu`1' using "temp.dta", nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                         5,526
        from master                     5,526  
        from using                          0  

    matched                                66  
    -----------------------------------------

. replace clu`1'=clu_new if clu_new!=.
(66 real changes made)

. drop clu_new

. 
. erase "temp.dta"

. erase "current.dta"

. cap erase "temp2.dta"

. 
end of do-file
missing matches per group #2

   ch_match |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      5,586       99.89       99.89
          1 |          4        0.07       99.96
          2 |          2        0.04      100.00
------------+-----------------------------------
      Total |      5,592      100.00
    4
(5586 missing values generated)
(5592 missing values generated)
mis2000 was str11 now str32
(5559 real changes made)
(6 real changes made)
(18 real changes made)
(0 real changes made)
(90 real changes made)
(0 real changes made)
    6
(6 real changes made)

. 
. *******************************************
. **** Auxiliary file 2: "matching.do"   ****
. **** matching of cluster-numbers       ****
. *******************************************
. **** Ehrl (2017) Estudos Economicos 47/1 ** 
. *******************************************
. 
. *** save the current data in use (to restore it later)
. save "current.dta", replace
(note: file current.dta not found)
file current.dta saved

. 
. *** keep only the two different group numbers
. keep clu`1' clu_new

. keep if clu_new!=.
(5586 observations deleted)

. sort clu`1' clu_new

. ** drop unecessary obs:
. drop if clu`1'==clu_new
(2 observations deleted)

. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
(0 observations deleted)

. 
. *** 1. check
. *** problem for several destinies (to be replaced by only 1 new clu-number)
.  count if clu`1'==clu`1'[_n-1]
    0

.  while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  save "temp.dta", replace
(note: file temp.dta not found)
file temp.dta saved

.  
.  *** 2. check if a problem will occur:
.  *** problem for cross-ref (a new cluster number is at the same time replaced b
> y another new one)
.  preserve 

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
. restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no:
. else {
. restore
. }

. 
. *** repeat this procedure several times
. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** final checks:
. assert clu`1'!=clu`1'[_n-1]

.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

.  assert r(N)==0

.  restore

. 
. // procedure is complete. restore data
. use "current.dta", clear

. 
. *** finally, replace cluster number of all mun of one group
. *** with the new number of the other group
. drop clu_new

. merge m:1 clu`1' using "temp.dta", nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                         5,574
        from master                     5,574  
        from using                          0  

    matched                                18  
    -----------------------------------------

. replace clu`1'=clu_new if clu_new!=.
(18 real changes made)

. drop clu_new

. 
. erase "temp.dta"

. erase "current.dta"

. cap erase "temp2.dta"

. 
end of do-file
missing matches per group #3

   ch_match |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      5,590       99.96       99.96
          1 |          2        0.04      100.00
------------+-----------------------------------
      Total |      5,592      100.00
    2
(5590 missing values generated)
(5592 missing values generated)
mis2000 was str17 now str32
(5563 real changes made)
(2 real changes made)
(18 real changes made)
(0 real changes made)
(90 real changes made)
(0 real changes made)
    2
(2 real changes made)

. 
. *******************************************
. **** Auxiliary file 2: "matching.do"   ****
. **** matching of cluster-numbers       ****
. *******************************************
. **** Ehrl (2017) Estudos Economicos 47/1 ** 
. *******************************************
. 
. *** save the current data in use (to restore it later)
. save "current.dta", replace
(note: file current.dta not found)
file current.dta saved

. 
. *** keep only the two different group numbers
. keep clu`1' clu_new

. keep if clu_new!=.
(5590 observations deleted)

. sort clu`1' clu_new

. ** drop unecessary obs:
. drop if clu`1'==clu_new
(1 observation deleted)

. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
(0 observations deleted)

. 
. *** 1. check
. *** problem for several destinies (to be replaced by only 1 new clu-number)
.  count if clu`1'==clu`1'[_n-1]
    0

.  while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  save "temp.dta", replace
(note: file temp.dta not found)
file temp.dta saved

.  
.  *** 2. check if a problem will occur:
.  *** problem for cross-ref (a new cluster number is at the same time replaced b
> y another new one)
.  preserve 

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
. restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no:
. else {
. restore
. }

. 
. *** repeat this procedure several times
. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** final checks:
. assert clu`1'!=clu`1'[_n-1]

.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

.  assert r(N)==0

.  restore

. 
. // procedure is complete. restore data
. use "current.dta", clear

. 
. *** finally, replace cluster number of all mun of one group
. *** with the new number of the other group
. drop clu_new

. merge m:1 clu`1' using "temp.dta", nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                         5,584
        from master                     5,584  
        from using                          0  

    matched                                 8  
    -----------------------------------------

. replace clu`1'=clu_new if clu_new!=.
(8 real changes made)

. drop clu_new

. 
. erase "temp.dta"

. erase "current.dta"

. cap erase "temp2.dta"

. 
end of do-file
missing matches per group #4

   ch_match |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      5,592      100.00      100.00
------------+-----------------------------------
      Total |      5,592      100.00
    0
(5592 missing values generated)
(5592 missing values generated)
mis2000 was str1 now str32
(5565 real changes made)
(0 real changes made)
(73 real changes made)
(0 real changes made)
(0 real changes made)

. 
. *******************************************
. **** Auxiliary file 2: "matching.do"   ****
. **** matching of cluster-numbers       ****
. *******************************************
. **** Ehrl (2017) Estudos Economicos 47/1 ** 
. *******************************************
. 
. *** save the current data in use (to restore it later)
. save "current.dta", replace
(note: file current.dta not found)
file current.dta saved

. 
. *** keep only the two different group numbers
. keep clu`1' clu_new

. keep if clu_new!=.
(5592 observations deleted)

. sort clu`1' clu_new

. ** drop unecessary obs:
. drop if clu`1'==clu_new
(0 observations deleted)

. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
(0 observations deleted)

. 
. *** 1. check
. *** problem for several destinies (to be replaced by only 1 new clu-number)
.  count if clu`1'==clu`1'[_n-1]
    0

.  while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  save "temp.dta", replace
(note: dataset contains 0 observations)
(note: file temp.dta not found)
file temp.dta saved

.  
.  *** 2. check if a problem will occur:
.  *** problem for cross-ref (a new cluster number is at the same time replaced b
> y another new one)
.  preserve 

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
. restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no:
. else {
. restore
. }

. 
. *** repeat this procedure several times
. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** 1. check:
. count if clu`1'==clu`1'[_n-1]
    0

. while r(N)!=0 {
  2.         replace clu`1'=clu_new if clu`1'==clu`1'[_n-1]
  3.         replace clu_new=clu_new[_n-1] if clu_new==clu`1'
  4.         sort clu`1' clu_new
  5.         // drop double obs. (in case)
.         drop if clu`1'==clu_new
  6.         drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
  7.         // to end the loop:
.         count if clu`1'==clu`1'[_n-1]
  8. }

.  
. *** 2. check if a problem will occur
.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

. // if yes:
.  if r(N)!=0 {
.  restore
. 
. rename clu_new clu_new2 
. rename clu`1' clu_new
. save "temp2.dta", replace
. use "temp.dta", clear
. merge m:1 clu_new using "temp2.dta", nogen
. replace clu_new2=clu_new if clu_new2==.
. keep if clu`1'!=.
. drop clu_new
. rename clu_new2 clu_new 
. sort clu`1' clu_new
. // drop unecessary obs:
. drop if clu`1'==clu_new
. drop if clu`1'==clu`1'[_n-1] & clu_new==clu_new[_n-1]
. save "temp.dta", replace
. }

. // if no
. else {
. restore
. }

. 
. *** final checks:
. assert clu`1'!=clu`1'[_n-1]
(null assertion)

.  preserve 

.  cap drop help

.  rename clu_new help

.  rename clu`1' clu_new

.  append using "temp.dta"

.  gsort clu_new -help, mfirst

.  count if clu_new==clu_new[_n+1] & help[_n+1]!=.
    0

.  assert r(N)==0

.  restore

. 
. // procedure is complete. restore data
. use "current.dta", clear

. 
. *** finally, replace cluster number of all mun of one group
. *** with the new number of the other group
. drop clu_new

. merge m:1 clu`1' using "temp.dta", nogen

    Result                           # of obs.
    -----------------------------------------
    not matched                         5,592
        from master                     5,592  
        from using                          0  

    matched                                 0  
    -----------------------------------------

. replace clu`1'=clu_new if clu_new!=.
(0 real changes made)

. drop clu_new

. 
. erase "temp.dta"

. erase "current.dta"

. cap erase "temp2.dta"

. 
end of do-file
missing matches per group

   ch_match |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |      5,592      100.00      100.00
------------+-----------------------------------
      Total |      5,592      100.00
    0
(27 missing values generated)

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
clu2000_fi~l |      5565    2183.341    1295.586          1       4300
clu1991_fi~l |      5507    2180.393     1301.37          1       4323
  clu2000 was float now int
  clu2000_final was float now int
  (22,368 bytes saved)
file _Crosswalk_2000.dta saved
      name:  <unnamed>
       log:  /Users/tomasdomingueziino/Dropbox/Research/jmp/current/data_new/shap
> efiles/raw/Ehrl_AMCgeneration_EE/_Crosswalk_1991_2010_2000.log
  log type:  text
 closed on:   8 Apr 2021, 10:38:02
---------------------------------------------------------------------------------
